package impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import dao.BaseDao;
import dao.FeedbackDao;
import entity.Feedback;
import entity.Visit;

public class FeedbackDaoImpl extends BaseDao implements FeedbackDao{

	@Override
	public int addFeedback(Feedback feedback) {
		String sql = "INSERT feedback (id,date,msg) VALUES(?,?,?)";
		Object[] objects = {feedback.getId(),feedback.getDate(),feedback.getMsg()};
		return execeteUpdata(sql, objects);
	}

	@Override
	public List<Feedback> allFeedback() {
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		String sql="SELECT * FROM feedback";
		List<Feedback> feedbacks=new ArrayList<Feedback>();
		try {
			conn=getConnection();
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				Feedback feedback=new Feedback();
				feedback.setDate(rs.getString("date"));
				feedback.setMsg(rs.getString("msg"));
				feedback.setId(rs.getString("id")); 
				feedbacks.add(feedback);
			}
		} catch (Exception e) {
		e.printStackTrace();
		}finally{
			closeAll(rs, pstmt, conn);
		}
		return feedbacks;
	}

}
